#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mx=100005;
int n;
ll ml[mx],cl[mx],mr[mx],cr[mx];
ll ans=3e9;
struct node{
	ll a,b;
}s[mx]; 
bool cmp(node x,node y)
{
	if(x.b==y.b) return x.a<y.a;
	return x.b<y.b;
}
int main()
{
	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%lld%lld",&s[i].a,&s[i].b);
	sort(s+1,s+n+1,cmp);
	ml[0]=cl[0]=mr[n+1]=cr[n+1]=2e9+7;
	for(int i=1;i<=n;i++)
	{
		if(i>1)
		{
			if(s[i].a<ml[i-1]) cl[i]=ml[i-1],ml[i]=s[i].a;
			else ml[i]=ml[i-1],cl[i]=min(cl[i-1],s[i].a);
		}
		else ml[i]=min(s[i].a,ml[i-1]),cl[i]=1e9+7;
	}
	for(int i=n;i>=1;i--)
	{
		if(i<n)
		{
			if(s[i].a+s[i].b<mr[i+1]) cr[i]=mr[i+1],mr[i]=s[i].a+s[i].b;
			else mr[i]=mr[i+1],cr[i]=min(cr[i+1],s[i].a+s[i].b);
		}
		else mr[i]=min(s[i].a+s[i].b,mr[i+1]),cr[i]=1e9+7;
	}
	for(int i=1;i<=n;i++)
	{
		ll res[4];
		for(int j=0;j<4;j++) res[j]=2e9+7;
		if(i>1) res[0]=s[i].b+ml[i-1];
		if(i>2) res[1]=s[i].b+cl[i-1];
		if(i<n) res[3]=mr[i+1];
		if(i<n-1) res[4]=cr[i+1];
		sort(res,res+4);
		ans=min(ans,s[i].a+res[0]+res[1]);
	}
	printf("%d\n",ans);
	return 0;
}

